<?php
require 'HashCode.php';

class Student
{
    use HashCode;

    //学生年级
    public $grade = null;
    //班级
    public $class = null;
    //姓氏
    public $firstName = null;
    //名字
    public $lastName = null;

    public function __construct($grade, $class, $firstName, $lastName)
    {
        $this->grade = $grade;
        $this->class = $class;
        $this->firstName = $firstName;
        $this->lastName = $lastName;
    }

    /**
     * 生成哈希值
     * 下面只是一个简单的展示过程，实际需要根据严格的数学运算来具体实现
     */
    public function hashCode(){
        $B = 31;
        $hash = 0;
        //对于小整型来说不需要转化
        $hash = $hash * $B + $this->grade;
        $hash = $hash * $B + $this->class;
        //对于字符串来说需要 hashCode 一下
        $hash = $hash * $B + $this->hashCode64(strtolower($this->firstName));
        $hash = $hash * $B + $this->hashCode64(strtolower($this->lastName));

        return $hash;
    }
}